package com.compunit.composite.a;

import java.net.URL;

import org.compunit.Provide;
import org.compunit.interfaces.IComponent;
import org.compunit.interfaces.IResourceRetriever;

import com.compunit.composite.a.interfaces.IStamper;

@Provide({IStamper.class})
public class Stamper implements IStamper {
	
	@Override
	public boolean activate(final IResourceRetriever handler) throws Exception {
		System.out.println("Stamper actived!");
		final URL url = handler.getResource("base.cx");
		System.out.println("base.cx URL: ".concat(url.toString()));
		final byte[] data = handler.getResourceBytes("base.cx");
		System.out.println("base.cx length: ".concat(String.valueOf(data.length)));
		return true;
	}

	@Override
	public boolean connect(final IComponent unit, final String interfaceName) throws Exception {
		return true;
	}

	@Override
	public void deactivate() throws Exception {
		System.out.println("Stamper shutting down.");
	}

	@Override
	public String getStamp() {
		final StringBuilder builder = new StringBuilder();
		builder.append("[TimeStamp:").append(System.currentTimeMillis()).append("] ");
		return builder.toString();
	}
}
